<?php defined('InNcPHP') or exit('Access Invalid!');?>
<style>
    .show { display: block; }
    .hide { display: none; }
    .layui-layer-title{color: red;}
</style>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['order_refund_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="order_refund" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> <?php echo $lang['order_index_order_sn'];?></label></th>
                <td><input type="text" name="search_sn" value="<?php echo $output['search']['search_sn']; ?>" class="txt"></td>
                <th><label> 手机号</label></th>
                <td><input type="text" name="search_phone" value="<?php echo $output['search']['search_phone']; ?>" class="txt"></td>
                <th><label>发起时间</label></th>
                <td><input type="text" name="search_stime" value="<?php echo $output['search']['search_stime']; ?>" id="search_stime" class="txt date"></td>
                <td><input type="text" name="search_etime" value="<?php echo $output['search']['search_etime']; ?>" id="search_etime" class="txt date"></td>
            </tr>
            <tr>
                <th><label> <?php echo $lang['order_index_status'];?></label></th>
                <td>
                    <select name="search_status">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['status'])): ?>
                            <?php foreach ($output['status'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo $output['search']['search_status'] === $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo '订单支付类型';?></label></th>
                <td>
                    <select name="order_type">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['pay_type'])): ?>
                            <?php foreach ($output['pay_type'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo $output['search']['pay_type'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search">&nbsp;</a>
                    <?php if ($output['search']['search_sn'] || $output['search']['search_phone'] ||$output['search']['search_stime'] || $output['search']['search_etime'] || $output['search']['search_merchant'] || $output['search']['pay_type'] || $output['search']['search_status']): ?>
                        <a href="index.php?act=order_refund&op=index" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a>
                    <?php endif; ?>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

    <a class="m-btn blue-stripe mini <?php echo ($_GET['search_status']=='')?'checked':'' ?> " onclick="parent.openItem('index,order_refund,trade');" href="#">全部订单</a>
    <a class="m-btn yellow-stripe mini <?php echo ($_GET['search_status']=='0')?'checked':'' ?>" onclick="parent.openItem('index,order_refund,trade,search_status=0');"  href="#">处理中</a>
    <a class="m-btn red-stripe mini  <?php echo ($_GET['search_status']==1)?'checked':'' ?> " onclick="parent.openItem('index,order_refund,trade,search_status=1');" href="#">通过</a>
    <a class="m-btn green-stripe mini <?php echo ($_GET['search_status']==2)?'checked':'' ?>" onclick="parent.openItem('index,order_refund,trade,search_status=2');"  href="#">不通过</a>


    <div style="text-align:right;"><a class="btns" target="_blank" href="index.php?<?php echo $_SERVER['QUERY_STRING'];?>&op=export"><span><?php echo $lang['nc_export'];?>Excel</span></a></div>
    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['order_index_order_sn']?></th>
            <th class="align-center">手机</th>
            <th class="align-center">退款理由</th>
            <th>订单支付方式</th>
            <th class="align-center">支付单号</th>
            <th class="align-center">发起时间</th>
            <th class="align-center"><?php echo $lang['order_index_status']?></th>
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <?php foreach($output['orders'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['order_sn']; ?></td>
                    <td class="align-center" ><?php echo $v['member_phone']; ?></td>
                    <td class="align-center"><?php echo $v['refund_type']; ?></td>
                    <td> <?php echo $output['pay_type'][$v['pay_type']]; ?></td>
                    <td class="align-center"><?php echo $v['pay_sn']; ?></td>
                    <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['addtimes']); ?></td>
                    <td class="align-center"><?php echo $output['status'][$v['status']]; ?></td>
                    <td class="align-center">
                        <a href="index.php?act=order_refund&op=detail&id=<?php echo $v['id']; ?>">查看</a>
                        <?php if ($v['status'] == 0 && $output['admin_info']['merchant_id']==0): ?>
                            <a href="###" onclick="check_edit(<?php echo $v['id']; ?>, $(this));">审核</a>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php } ?>
        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
    <!-- 审核表单 -->
    <form id="refund_edit" method="post" class="hide">
        <input type="hidden" name="refund_id">
        <table class="table tb-type2">
            <tbody>
            <!-- 日期 -->
            <tr>
                <td style="width: 100px;" class="required"><label class="validation">手机:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform phone"></td>
                <td class="vatop tips"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation">退款理由:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform refund_type"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation">退款说明:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform note"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation">退款金额:</label><span class="pay_type">(退款至微信)</span></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform refund_money"></td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation">处理备注:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <textarea id="replay" name="replay" class="txt" style="width:70%;height: 100px;"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="required"><label class="validation">是否同意退款:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select id="status" name="status" class="class-select">
                        <option value="1">同意</option>
                        <option value="2">不同意</option>
                    </select>
                </td>
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="editSubmit"><span><?php echo $lang['nc_update'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script>
    //开始日期
    $('#search_stime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_etime").datepicker("option", "minDate", selectedDate);
        }
    });
    //结束日期
    $('#search_etime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_stime").datepicker("option", "maxDate", selectedDate);
        }
    });

    //编辑的表单
    var editForm = $('#refund_edit');
    function check_edit(orderId,obj)
    {
        $("#replay").val('');
        $.post('index.php?act=order_refund&op=ajax_detail', {id: orderId}, function (data) {
            editForm.find('input[name="refund_id"]').val(data.id);
            editForm.find(".phone").text(data.member_phone);
            editForm.find(".refund_type").text(data.refund_type);
            editForm.find(".refund_money").text(data.refund_money);
            editForm.find(".note").text(data.note);
            if(data.pay_type==1){
                editForm.find(".pay_type").text('(退款至微信)');
            }else if(data.pay_type==2){
                editForm.find(".pay_type").text('(退款至支付宝)');
            }else{
                editForm.find(".pay_type").text('(后台手动确认收款)');
            }
            layer.open({
                type: 1,
                title: '审核退款订单(请谨慎操作,同意退款操作订单金额将直接原路返回至客户账户中）',
                area: ['700px', '410px'],
                content: editForm,
                cancel: function () {
                    $('label.error').hide();
                    //editForm.find('input.error').removeClass('error');
                }
            });
        }, 'json');
    }

    //提交编辑表单
    $("#editSubmit").click(function(){
        if($("#replay").val()==''){
            layer.alert('处理备注不能为空');
            return;
        }
        layer.confirm('确认您的审核操作？', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        },function(index){
            $.post('index.php?act=order_refund&op=audit_refund',editForm.serialize(),function(data){
               if(data.res){
                   layer.alert('<?php echo $lang['nc_common_update_succ']; ?>', function () {
                       location.reload();
                   });
               }else{
                   layer.alert(data._msg);
               }
            },'json');
            layer.close(index);
        })
    })

    //确认收款
    function check_money(orderId, obj) {
        layer.confirm('确认收到款项？', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=order&op=check_money', {id:orderId},function (data) {
                if (data.res) {
                    obj.parent().prev().text('<?php echo $output['status']['20']; ?>');
                    obj.remove();
                } else {
                    layer.alert(data._msg);
                }
                layer.close(index);
            }, 'json');
        });
    }
</script>
